const { PrismaClient } = require('@prisma/client')
var rewire = require("rewire")
const config = rewire('./config.cjs')
var { Sitdown } = require('sitdown')
const redis = require("redis")
const { readFile } = rewire('./common/file.cjs')
var COS = require('cos-nodejs-sdk-v5')
const DbClient = require('ali-mysql-client')

const cos = new COS(config.tencentCloud)

function getCosClient() {
  return cos
}

// DB
const prisma = new PrismaClient()

function getPrisma() {
  return prisma
}

const db = new DbClient(config.dbconfig)
function getDb() {
  return db
}

// 用来做html转markdown
const sitdown = new Sitdown()
function getSitdown() {
  return sitdown
}

// 获取随机赞美语
async function getRandomGreeting() {
  const greetingStr = readFile(config.rootPath + '/social/doc/greetings')
  const strarr = greetingStr.split("\n")
  const i = ramdomRange(0, strarr.length)
  return strarr[i]
}

module.exports = {getPrisma, getDb, getRandomGreeting, getSitdown, getDb, getCosClient}
